package com.intelligent.health.member.controller;

import com.intelligent.health.member.pojo.User;
import com.intelligent.health.member.service.MemberService;
import entity.R;
import entity.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: torlesse-liang
 * @Date: 2022/03/17/22:40
 * @Description: 注册控制器
 */
@Slf4j
@RestController
@RequestMapping("/register")
public class RegisterController {

    @Autowired
    private MemberService memberService;

    /**
     * 用户注册--网页端 账号密码注册
     *
     * @param user 用户注册信息
     */
    @PostMapping("/web")
    public R registerByWebSite(@RequestBody User user) {
        try {
            memberService.addMember(user);
        } catch (Exception e) {
            log.error("网页端账号注册失败: {}", user);
            return R.setResult(ResultCodeEnum.REGISTER_ERROR);
        }
        log.info("网页端账号注册成功: {}", user);
        return R.setResult(ResultCodeEnum.REGISTER_SUCCESS);
    }
}
